/*
 * Image.h
 *
 *  Created on: Jul 7, 2009
 *      Author: kurt
 */

#ifndef IMAGE_H_
#define IMAGE_H_

#include "Resizable2DInterface.h"

namespace objdraw 
{

class Image: public objdraw::Resizable2DInterface 
{
	public:
		typedef struct PaletteData
		{
			bool in_vram;
			short pixelFormat;
			short nentries;
			unsigned int * data;
			unsigned int size;
		} __PaletteData;
		
		typedef struct ImageData
		{
			bool in_vram;
			bool swizzled;
			short pixelFormat;
			int width;
			int height;
			int textureWidth;// the real width of data, 2^n with n>=0
			int textureHeight; // the real height of data, 2^n with n>=0
			unsigned int * data;
			unsigned int size;
			PaletteData * palette;
		} __ImageData;
	protected:
		virtual ~Image();
		std::string error;
		bool mirroredVert, mirroredHori;
	public:
		ImageData * image;
		static PaletteData * CreatePalette(int size, bool in_vram, short pixelFormat);
		
//		Image();
		Image(Image const & r);
		Image(DrawingCanvas * c = NULL);
		
		virtual void render();
		virtual void render_big();
		
		uint getPixel(uint x, uint y);
		void setPixel(uint x, uint y, uint pixel);
		
		uint getImageWidth();
		uint getImageHeigth();
		
		virtual void swizzle();
		virtual void unswizzle();
		virtual bool swizzled();
		
		bool isMirroredVert();
		bool isMirroredHori();
		void mirrorVert();
		void mirrorHori();
		void setVertMirror(bool mir);
		void setHoriMirror(bool mir);
//		TODO virtual std::string toString();
		friend class ImageUtil;
};

}

#endif /* IMAGE_H_ */
